package com.cyq.day20.employee;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Arrays;

public class LoginFrame extends JFrame {
    static String userName="aaaaaa";
    static char[] password=new char[]{65,65,65,65,65,65};
    public LoginFrame(){
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setTitle("登录");
        setLayout(new FlowLayout());
        //用户名框
        JLabel label1 = new JLabel();
        label1.setText("用户名:");
        add(label1);
        //用户名输入框
        JTextField textField = new JTextField(20);
       add(textField);
        //密码框
        JLabel label2 = new JLabel();
        label2.setText("密码:");
        add(label2);
        //密码输入框
        JPasswordField passwordField = new JPasswordField(20);
        add(passwordField);
        //登录按钮
        JButton button1 = new JButton();
        button1.setText("登录");
       add(button1);
        //清空按钮
        JButton button2 = new JButton();
        button2.setText("清空");
        add(button2);
        button1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (textField.getText().equals(userName) && Arrays.equals(passwordField.getPassword(), password)) {
                    JOptionPane.showMessageDialog(null, "登录成功");
                    //com.cyq.day19.qq.MySwing mySwin=new com.cyq.day19.qq.MySwing(textField.getText());
                    //mySwin.setVisible(true);
                    LoginFrame.this.dispose();
                } else {
                    JOptionPane.showMessageDialog(null, "用户名或密码错误");
                }
            }
        });
    }
}
